package com.cyandpos.pad.cateringformat.morefunction;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;

import com.cyandpos.pad.R;
import com.cyandpos.pad.activity.BankPayActivity;
import com.cyandpos.pad.activity.ClearTableActivity;
import com.cyandpos.pad.activity.LockActivity;
import com.cyandpos.pad.activity.ModifyPasswordActivity;
import com.cyandpos.pad.activity.OpenCashboxActivity;
import com.cyandpos.pad.activity.OrderFoodActivity;
import com.cyandpos.pad.activity.OrderFoodInfoActivity;
import com.cyandpos.pad.activity.QueryGoodsActivity;
import com.cyandpos.pad.activity.ReportActivity;
import com.cyandpos.pad.activity.ReprintTicketActivity;
import com.cyandpos.pad.cateringformat.BaseFragment;
import com.cyandpos.pad.common.ManagerCardManager.MangerCardData;
import com.cyandpos.pad.common.commondata.Constant;
import com.cyandpos.pad.common.commondata.MainSaleConstant;
import com.cyandpos.pad.common.commondata.SktConfigConstant;
import com.cyandpos.pad.morefunction.CashCollectionPresenter;
import com.cyandpos.pad.morefunction.ICashMainSaleView;
import com.cyandpos.pad.morefunction.PayGridMainSaleAdapter;
import com.cyandpos.pad.morefunction.PayGridView;
import com.cyandpos.pad.utils.PermissionsUtils;
import com.cyandpos.pad.utils.ToastUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by xin on 2021/8/31
 * desc:
 */
public class MorefunctionFragment extends BaseFragment implements ICashMainSaleView  {
    private PayGridMainSaleAdapter payAdapter;

    @BindView(R.id.gv_act_sale)
    PayGridView gv_act_sale;

    Unbinder unbinder;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_more_function_main, container, false);
        unbinder = ButterKnife.bind(this, view);
        Context context = view.getContext();
        initData();
        return view;
    }

    private void initData() {
        getVisLayout();

    }

    public void getVisLayout(){

        PermissionsUtils.visPermission(null,getActivity(), SktConfigConstant.VIS_MainSale, SktConfigConstant.MainSale_ALL, new PermissionsUtils.PermissionListener() {
            @Override
            public void onPermissionSuccess(MangerCardData mangerCardData, int flag) {
                String name = mangerCardData.getName();
                String[] split = name.split(";");

                new CashCollectionPresenter(MorefunctionFragment.this).getnMainSaleList(split);

            }
            @Override
            public void onPermissionFaild(String msg) {
                ToastUtils.showMsg("缺少功能权限"+msg);

            }
        });
    }
    @Override
    public void showPaymetListData(List<Integer> imgs, List<Integer> select_imgs, final List<String> names) {
        payAdapter = new PayGridMainSaleAdapter(getActivity(), imgs, select_imgs, names);
        gv_act_sale.setAdapter(payAdapter);
        gv_act_sale.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                switch (names.get(i)){
                    case MainSaleConstant.MAIN_TIH_NAME: {//提货
                    }
                    break;
                    case MainSaleConstant.MAIN_CDXP_NAME: {// 重打小票
                        Intent intent= new Intent(getActivity(),ReprintTicketActivity.class);
                        startActivity(intent);
                    }
                    break;
                    case MainSaleConstant.MAIN_DZ_NAME: { // 班报日报
                        Intent intent= new Intent(getActivity(),ReportActivity.class);
                        startActivity(intent);
                    }
                    break;
                    case MainSaleConstant.MAIN_YHGN_NAME: {// 银行功能
                        Intent intent= new Intent(getActivity(),BankPayActivity.class);
                        startActivity(intent);

                    }

                    break;
                    case MainSaleConstant.MAIN_HYGN_NAME: {// 会员功能
                       getActivity().setResult(Constant.MORE_FUNCTION_TO_MAIN_ADD_MEMBER_RETID, new Intent());

                    }
                    break;

                    case MainSaleConstant.MAIN_SPCX_NAME: {// 商品查询
                        Intent intent= new Intent(getActivity(),QueryGoodsActivity.class);
                        startActivity(intent);
                    }
                    break;
                    case MainSaleConstant.MAIN_JYMX_NAME: {// 交易明细

                    }
                    break;
                    case MainSaleConstant.MAIN_TUIH_NAME: {// 退货

                    }
                    break;
                    case MainSaleConstant.MAIN_XTGN_NAME: {// 系统功能

                    }
                    break;
                    case MainSaleConstant.MAIN_ZDQX_NAME: {// 整单取消

                    }
                    break;
                    case MainSaleConstant.MAIN_DDCX_NAME: {// 订单查询

                    }
                    break;
                    case MainSaleConstant.MAIN_ZDZK_NAME: {// 整单折扣
                    }
                    break;

                    case MainSaleConstant.MAIN_FJCX_NAME: {//附加查询

                    }
                    break;

                    case MainSaleConstant.MAIN_SP_NAME: {//锁屏
                        startActivity(new Intent(getActivity(), LockActivity.class));
                    }
                    break;

                    case MainSaleConstant.MAIN_XGKL_NAME: {//修改口令
                        startActivity(new Intent(getActivity(), ModifyPasswordActivity.class));
                    }
                    break;
                    case MainSaleConstant.MAIN_GD_NAME: {//挂单

                    }
                    break;

                    case MainSaleConstant.MAIN_QD_NAME: {//取单

                    }
                    break;

                    case MainSaleConstant.MAIN_FSTH_NAME: {//负数退货

                    }
                    break;

                    case MainSaleConstant.MAIN_TJXP_NAME: {//添加小票

                    }
                    break;
                    case MainSaleConstant.MAIN_DKQX_NAME: {//打开钱箱
                        Intent intent =new Intent(getActivity(),OpenCashboxActivity.class);
                        startActivity(intent);

                    }
                    break;
                    case MainSaleConstant.MAIN_DJD_NAME: {//订金单

                    }
                    break;
                    case MainSaleConstant.MAIN_FY_NAME: {//关于

                    }

                    break;
                    case MainSaleConstant.MAIN_YD_NAME: {//餐饮预定
                        Intent intent =new Intent(getActivity(),OrderFoodActivity.class);
                        startActivity(intent);
                    }
                    break;
                    case MainSaleConstant.MAIN_QZ_NAME: {//餐饮清桌
                        Intent intent =new Intent(getActivity(),ClearTableActivity.class);
                        startActivity(intent);


                    }
                    break;
                    case MainSaleConstant.MAIN_YDXQ_NAME: {//预定详情
                        Intent intent =new Intent(getActivity(),OrderFoodInfoActivity.class);
                        startActivity(intent);
                    }
                    break;


                    default:
                        break;
                }
            }
        });

    }
}
